<?php
//统计类
class Zyk_tj
{
	//统计数目
	public static function count($table,$where){
		$model = new Model($table);
		return $model->where($where)->count();
	}

	//统计总和
	public static function sum($table,$zdz,$where){
		$model = new Model($table);
		return $model->fields("sum($zdz) as jsh")->where($where)->find()['jsh'];
	}

	//取值函数
	public static function zyk_info($tab,$id,$zdz){
        $model=new Model($tab);
        $uin = $model->fields($zdz)->where("id=".$id)->find()[$zdz];
        return $uin;
	}
	public static function c_info($id,$zdz){
        $model=new Model("customer");
        $uin = $model->fields($zdz)->where("user_id=".$id)->find()[$zdz];
        return $uin;
	}

	//取得相差时间(天)的日期
	public static function time($date,$day){
		return  date("Y-m-d",(strtotime($date) + $day*3600*24));
	}
	//取得两时间的差值
	public static function ctime($t1,$t2,$lx){
		$timediff=strtotime($t2)-strtotime($t1);
		$remain = $timediff % 86400;
		switch ($lx) {
			case 'd':
				$num=intval($timediff/86400) ;//相差天数
				break;
			case 'h':
				// $num=floor((strtotime($t2)-strtotime($t1))%86400/3600) ;//相差小时
				// $num=$remain/3600 ;//相差小时
				$num=($timediff/86400*24) ;//相差小时
				break;
		}
		return $num;
	}

	//随机生成PIN码
	function createRandomStr($length){ 
		$str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';//36个字符 
		$strlen = 36; 
		while($length > $strlen){ 
			$str .= $str; 
			$strlen += 36; 
		} 
			$str = str_shuffle($str); 
			return substr($str,0,$length); 
		}
	}

?>